package com.example.springdemo;

import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

@RestController
@RequestMapping("/wms/web/auth")
public class AuthController {

    @CrossOrigin
    @GetMapping(value = "/get_plant_menu")
    public Object get_plant_menu(Object request) {
        // 指定资源路径（相对于classpath根目录）
        try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("get_plant_menu.json")) {
            if (inputStream == null) {
                return "File not found.";
            }
            // 将输入流转换为字符串
            return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @CrossOrigin
    @GetMapping(value = "/get_location_tree")
    public Object get_location_tree() {
        // 指定资源路径（相对于classpath根目录）
        try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("get_location_tree.json")) {
            if (inputStream == null) {
                return "File not found.";
            }
            // 将输入流转换为字符串
            return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @CrossOrigin
    @PostMapping(value = "/get_home_notice_list")
    public Object get_home_notice_list() {
        //return "未实现";
        return "{\"returnCode\":1,\"returnMsg\":\"成功\",\"data\":\"d4505efd-10ae-42ba-a4bb-d7b7223fa106\"}";
    }

    @CrossOrigin
    @GetMapping(value = "/count/0")
    public Object count() {
        //return "未实现";
        return "{\"returnCode\":1,\"returnMsg\":\"成功\",\"data\":\"d4505efd-10ae-42ba-a4bb-d7b7223fa106\"}";
    }

    @CrossOrigin
    @PostMapping(value = "/get_new_notice")
    public Object get_new_notice() {
//       return "未实现";
        return "{\"returnCode\":1,\"returnMsg\":\"成功\",\"data\":\"d4505efd-10ae-42ba-a4bb-d7b7223fa106\"}";
    }

    @CrossOrigin
    @PostMapping(value = "/get_my_todo_receipt_count_list")
    public Object get_my_todo_receipt_count_list() {
        //return "未实现";
        return "{\n" +
                "    \"returnCode\": 1,\n" +
                "    \"returnMsg\": \"成功\",\n" +
                "    \"data\": [\n" +
                "        {\n" +
                "            \"receiptType\": 95,\n" +
                "            \"resourcesCode\": \"web_repair_input\",\n" +
                "            \"count\": 3,\n" +
                "            \"resourceName\": \"送修接收\",\n" +
                "            \"todoParamList\": [],\n" +
                "            \"url\": \"\"\n" +
                "        }\n" +
                "    ]\n" +
                "}";
    }

    @CrossOrigin
    @GetMapping(value = "/get_all_unit")
    public Object get_all_unit() {
        // 指定资源路径（相对于classpath根目录）
        try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("get_all_unit.json")) {
            if (inputStream == null) {
                return "File not found.";
            }
            // 将输入流转换为字符串
            return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}





